<template>
	<view class="art">
		<view class="title">
			<input class="uni-input" confirm-type="search" v-model="articleTitle" placeholder="请编写您的文章标题" />
		</view>
		<view class="content"> 
			<!-- <cu-editor ref="editor" :url="uploadUrl" :header="header" :content="content" @before="onUploadBefore" @update="onUpdate" @save="onSave"></cu-editor> -->
			<input class="uni-input" confirm-type="search" v-model="articleContent" placeholder="请编写您的文章内容" />
		</view>
		<view class="touxiangicon"   @click="uploadImg">
			<image  class="huiyuan_img" :src="feedbackFile" v-model="feedbackFile"></image>
		</view>
		<view class="up">
			<button size="mini" type="primary" @click="getNews" plain>提交</button>
		</view>
	</view>
</template>

<script>
	// import cuEditor from '@/components/cu-editor/cu-editor'
	export default {
		components:{
			// cuEditor
		},
		data() {
			return {
				content:'',
				articleTitle: '',
				articleContent: '',
				feedbackFile: '',
				datas: [],
			}
		},
		methods: {
			getNews(){
				console.log(this.con)
				uni.request({
				    url: `http://localhost:7000/bbs/bbs/addArticle/`, //接口地址。
					data:{
						userId:999,
						userName:'思思',
						articleTitle:this.articleTitle,
						articleContent:this.articleContent,
						articleFile:this.feedbackFile,
					},
					method:'POST',
				    success: (res) => {
				        console.log(res)
				    }
				});
			},
			getContents(html){
				console.log(html)
			},
			uploadImg(){
			    uni.chooseImage({
			        count: 1, //默认9
			        sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
			        sourceType: ['album'], //从相册选择
			        success:res => {
			            this.feedbackFile = res.tempFilePaths[0]
			            //上传给后台
			            uni.uploadFile({
			                url:'http://localhost:7000/bbs/bbs/updateFile',
			                filePath: res.tempFilePaths[0],
							name: 'file',
			                success: (uploadFileRes) => {
								// this.feedbackFile = uploadFileRes.data.data
								this.datas = uploadFileRes.data.split(",")
								let msg = this.datas[1].split("\"")[3]
								let badMsg = this.datas[1].split("\"")[4]
								let status = this.datas[2].split("\"")[3]
								if ( status == 200 ){
									this.feedbackFile = this.datas[0].split("\"")[3]
									uni.showToast({
										title: msg,
										duration: 2000
									});
								}else{
									uni.showToast({
										title: badMsg,
										duration: 2000
									});
								}
								
			                }
			            })
			        }	
			    });
			},
		}
	}
</script>

<style lang="scss">
	.art{
		.uni-input{
			margin-bottom: 30rpx;
		}
		// display: flex;
		margin: 30rpx;
		.content{
			height: 30rpx;
			margin-bottom: 30rpx;
		}
		.up{
			margin-top: 50rpx;
			height: 50rpx;
			width: 500rpx;
		}
	}
</style>
